package com.ej.demo.page;

import com.ej.demo.page.eJTestBase;
import com.thoughtworks.selenium.Selenium;

import static org.testng.AssertJUnit.*;

public class FlightListingPage {

	private Selenium selenium;

	public FlightListingPage() {
		selenium = eJTestBase.getSeleniumObj();
	}

	public void verifyFlightListing() {
		Selenium selenium = eJTestBase.getSeleniumObj();
		assertEquals(selenium.getTitle(), "easyJet - Step 1 - Flights");
	}

	public void selectOnwardJourneyFlight(String onwardFlight) {
		selenium.click(onwardFlight);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}

	public void selectReturnJourneyFlight(String returnFlight) {
		selenium.click(returnFlight);
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void verifyFlightSelection() {
		assertEquals(selenium.getText("//li[1]/strong"), "21 November 2009");
		assertEquals(
				selenium
						.getText("//div[@id='basketFlight_2281915']/div[2]/ul/li[1]/strong"),
				"28 November 2009");
	}

	public void navigateToFlightOptionPage() {
		String continueButton = "//a[@id='btnContinue']/span";
		selenium.click(continueButton);
		selenium.waitForPageToLoad("30000");
		assertEquals(selenium.getTitle(), "easyJet - Step 2 - Flight options");
	}

}
